home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 926 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: peachy.apana.org.au!grahamb
  2. From: grahamb@peachy.apana.org.au (Graham Broadbridge)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Beginner needs advice about FILE I/O.
  5. Date: 10 Jan 1996 09:13:45 GMT
  6. Organization: The Peachy Linux Node!
  7. Message-ID: <4d0009$q73@peachy.apana.org.au>
  8. References: <4bu4i1$e0b@budapest.ozonline.com.au>
  9. NNTP-Posting-Host: peachy.apana.org.au
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. cdowd@ozonline.com.au wrote:
  13. : I need to edit a file that consists of n number of a structure.
  14. : I can't see any way to directly delete files from a file stream
  15. : via it's FILE pointer. Is this possible?
  16.  
  17. Not directly.
  18.  
  19. : I could fread() the structures from the stream and make a linked 
  20. : list or copy the structures between FILE pointers and not copy the 
  21. : file to be deleted. Which would be better? What other alternatives 
  22. : do I have?
  23.  
  24. A simple method is to simply add a flag to the structure which 
  25. indicates whether this record is deleted, and ignore the record during
  26. any subsequent processing.
  27.  
  28. After a while (or prior to program termination) you could have a routine 
  29. that compacts the file by reading in and subsequently writing out to a 
  30. temp file all records for which the flag is false.  Then copy the temp 
  31. file over the original file, and then depending upon the success of the copy 
  32. operation unlink the temp file.
  33.  
  34. --
  35. +----------------------------------------------------------------------------+
  36.   Graham Broadbridge        Internet <graham@peachy.apana.org.au>
  37.   Marsfield   NSW                    <vk2yui@amsat.org>
  38.   Australia                 amprnet  <vk2yui@gw.vk2yui.ampr.org>
  39. +----------------------------------------------------------------------------+
  40.